package com.ygqh.baby.service.impl;
import java.util.List;
import  com.ygqh.baby.ao.QueryInfo;
import  com.ygqh.baby.ao.ResultSet;
import  com.ygqh.baby.po.AdminSupplementContractDetail;
import  com.ygqh.baby.mapper.AdminSupplementContractDetailMapper;
import  com.ygqh.baby.service.AdminSupplementContractDetailService;
import  org.springframework.util.Assert;
import java.util.Arrays;
import  org.springframework.stereotype.Service;
import  org.springframework.beans.factory.annotation.Autowired;

import  com.ygqh.baby.po.AdminSupplementContractDetailExample;
import  com.ygqh.baby.ao.DataStatus;

@Service
public class AdminSupplementContractDetailServiceImpl implements AdminSupplementContractDetailService{
	
	@Autowired
	private AdminSupplementContractDetailMapper adminSupplementContractDetailMapper;
	
	@Override
	public List<AdminSupplementContractDetail> find() {
		AdminSupplementContractDetailExample example = new AdminSupplementContractDetailExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return adminSupplementContractDetailMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		AdminSupplementContractDetailExample example = new AdminSupplementContractDetailExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return adminSupplementContractDetailMapper.countByExample(example);
	}

	@Override
	public AdminSupplementContractDetail findById(Long id) {
		return adminSupplementContractDetailMapper.selectByPrimaryKey(id);
	}


	

	@Override
	public int save(AdminSupplementContractDetail adminSupplementContractDetail) {
		return adminSupplementContractDetailMapper.insertSelective(adminSupplementContractDetail);
	}

	@Override
	public int update(AdminSupplementContractDetail adminSupplementContractDetail) {
		return adminSupplementContractDetailMapper.updateByPrimaryKeySelective(adminSupplementContractDetail);
	}

	@Override
	public ResultSet<AdminSupplementContractDetail> search(QueryInfo queryInfo,String q) {
		List<AdminSupplementContractDetail>  list =  adminSupplementContractDetailMapper.selectSuper(queryInfo, q);
		int count = adminSupplementContractDetailMapper.countSuper(q);
		ResultSet<AdminSupplementContractDetail> resultSet = new ResultSet<AdminSupplementContractDetail>(count,list);
		return resultSet;
	}

	@Override
	public int deleteSoft(Long[] ids) {
		Assert.notEmpty(ids);
		AdminSupplementContractDetailExample example = new AdminSupplementContractDetailExample();
		example.createCriteria().andIdIn(Arrays.asList(ids));
		AdminSupplementContractDetail record = new AdminSupplementContractDetail();
		record.setStatus(DataStatus.Delete);

		return adminSupplementContractDetailMapper.updateByExampleSelective(record, example);
	}
	
	@Override
	public int deleteSoft(Long id) {
		return this.deleteSoft(new Long[]{id});
	}

	@Override
	public int saveOrUpdate(AdminSupplementContractDetail adminSupplementContractDetail) {
		int r = 0;
		if(adminSupplementContractDetail.getId() != null) {
			r = this.update(adminSupplementContractDetail);
		}else {
			r = this.save(adminSupplementContractDetail);
		}
		return r;
	}

}

